from appium import webdriver
import time
import base64

# 初始化一个driver对象
desired_caps = {
    'platformName':'Android',
    'platformVersion': '7.1.2',
    'deviceName': 'emulator-5554',
    'appPackage': 'com.android.settings',
    'appActivity': '.Settings'
}
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
# time.sleep(2)
# driver.start_activity("com.android.settings", ".Settings")
# # 卸载手机中的app
# driver.remove_app("com.tencent.wework")
# # 上传本地app安装包并安装app
# driver.install_app(r"C:\TT\习知\课件\我的课件\app自动化\WeCom_android_4.0.19.20104_100001.apk")
# # 判断app是否安装
# print(driver.is_app_installed("com.tencent.wework"))
# # 发送文件到手机
# with open(r'.\my_demo.txt', encoding='utf-8') as f:
#     data = f.read()
# print(data)
# data = str(base64.b64encode(data.encode('utf-8')),'utf-8')
# print(data)
# driver.push_file('/sdcard/demo-12.txt', data)
# # 从手机中拉取文件
# data = driver.pull_file('/sdcard/demo-12.txt')
# print(data)
# data = str(base64.b64decode(data), 'utf-8')
# print(data)
# 获取当前页面结构
print(driver.page_source)
time.sleep(5)

driver.quit()